<style>
    @media screen and (max-width: 500px) {

        .layui-table-view {
            width: 100% !important;
            overflow-x: scroll !important;
            left: 0 !important;
        }

        .layui-table-box {
            width: 1200px !important;
            box-sizing: border-box;
        }

        .layui-layer.layui-layer-page {
            width: 100% !important;
            overflow: hidden !important;
            left: 0 !important;
        }

        .layui-layer-title {
            width: 100% !important;
            box-sizing: border-box;
        }

        .layui-layer-content {
            width: 100% !important;
        }

    }

    .w100 {
        width: 100px !important;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label w100">报修单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="repair_id" lay-verify="title" placeholder="请输入报修单号" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label w100">订单编号：</label>
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="bill_id" lay-verify="title" placeholder="请输入订单编号" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label w100">申请时间：</label>
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="date" id="date" placeholder="开始时间 到 结束时间" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label w100">用户手机号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="mobile" lay-verify="title" placeholder="请输入完整手机号码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label w100">状态：</label>
            <div class="layui-input-inline seller-inline-3">
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">未审核</option>
                    <option value="2">审核通过</option>
                    <option value="3">审核拒绝</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i
                    class="iconfont icon-chaxun"></i>筛选</button>
            <!-- <button class="layui-btn layui-btn-sm" lay-submit lay-filter="export-aftersales"><i
                    class="iconfont icon-clouddownload" style="font-size: 20px !important;"></i>导出</button> -->
        </div>
    </div>
</form>

<div class="table-body">
    <table id="deviceLogRepair" lay-filter="test"></table>
</div>
<div id="exportAftersales" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先选中或筛选要导出的订单
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        //时间插件
        layui.laydate.render({
            elem: '#date',
            range: '到',
            format: 'yyyy-MM-dd'
        });
        layui.table.render({
            elem: '#deviceLogRepair',
            height: 'full-160',
            cellMinWidth: '80',
            page: 'true',
            limit: '{:config('zlserver.page_limit')}',
            url: "{:url('deviceLogRepair/index')}?_ajax=1",
            id: 'deviceLogRepair',
            cols: [[
                { type: 'numbers' },
                { field: 'repair_id', width: 160, sort: true, title: '报修单号' },
                { title:'订单编号', width:200, templet:function(data){
                    var html = '<a class="link-hot option-show" data-id="' + data.bill_id + '">'+data.bill_id+'</a>';
                    return html;
                }},
                { field: 'status_name', width: 100, title: '状态' },
                { field: 'user_id', width: 150, minWidth: 50, title: '用户' },
                { field: 'reason', width: 300, title: '原因' },
                { field: 'ctime', width: 170, title: '申请时间' },
                {
                    field: 'operating', title: '操作', width: 120, align: 'center', templet: function (data) {
                        var html = '';
                        if (data.status == 1) {
                            html += '<a  class="layui-btn layui-btn-xs option-audit" data-id="' + data.repair_id + '">操作</a>';
                        }
                        html += '<a  class="layui-btn layui-btn-xs option-view layui-btn-primary" data-id="' + data.repair_id + '">明细</a>';
                        return html;
                    }
                },
            ]]
        });
        
        //点击跳转到对应菜单
        $(document).on('click','.option-show',function(){
            var id = $(this).attr('data-id');
            
            // 打开一个查看设备日志的新页面
            var url = "{:url('manage/DeviceLog/Index')}" + '?bill_id=' + id;
            var topLayui = parent === self ? parent.window.layui : top.parent.window.layui;
            topLayui.index.openTabsPage(url, '设备日志'); 
            return false;
        });

        layui.form.on('submit(*)', function (data) {
            layui.table.reload('deviceLogRepair', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //审核操作
        $(document).on('click', '.option-audit', function () {
            JsGet("{:url('deviceLogRepair/audit')}?repair_id=" + $(this).attr('data-id'), function(e){
                if ((e.hasOwnProperty('status') && !e.status) || (e.hasOwnProperty('code') && e.code == 0)) {
                    layer.msg(e.msg); return false;
                }

                window.box = layer.open({
                    type: 1,
                    content: e.data,
                    area: ['600px', '460px'],
                    title: '报修单审核',
                    btn: ['确认', '取消'],
                    yes: function (index, layero) {
                        $.ajax({
                            type: 'post',
                            url: "{:url('deviceLogRepair/audit')}",
                            data: $('#aftersales_form').serialize(),
                            success: function (res) {
                                if (res.status) {
                                    layer.msg('保存成功');
                                    window.setTimeout("window.location.reload();", 500);     //如果想做的更好就关掉弹出框，然后表格重新加载即可
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        });
                    }
                });
            });
        });
        //查看操作
        $(document).on('click', '.option-view', function () {
            JsGet("{:url('deviceLogRepair/view')}?repair_id=" + $(this).attr('data-id'), function(e){
                if ((e.hasOwnProperty('status') && !e.status) || (e.hasOwnProperty('code') && e.code == 0)) {
                    layer.msg(e.msg); return false;
                }

                if (e.status) {
                    window.box = layer.open({
                        type: 1,
                        content: e.data,
                        area: ['600px', '400px'],
                        title: '报修单查看'
                    });
                } else {
                    layer.msg(e.msg);
                }
            });
        });
        //报修单导出
        layui.form.on('submit(export-aftersales)', function (data) {

            layer.open({
                type: 1,
                title: '报修单导出',
                area: ['400px', '248px'], //宽高
                btn: ['确定', '取消'],
                content: $("#exportAftersales").html(),
                yes: function () {
                    //判断是否有选中
                    var checkStatus = layui.table.checkStatus('deviceLogRepair');
                    var checkData = checkStatus.data;
                    var length = checkStatus.data.length;
                    var ids = [];
                    if (length) {
                        $.each(checkData, function (i, obj) {
                            ids.push(obj.repair_id);
                        });
                    }

                    //判断是否有选中
                    var filter = $(".seller-form").serialize();
                    filter += '&ids=' + ids;
                    $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                    var data = $(".export-form:last").serializeArray();

                    data.push({ 'name': 'model', 'value': 'DeviceLogRepair' });

                    JsPost("{:url('Ietask/export')}", data, function (res) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            if (res.status) {
                                layui.table.reload('deviceLogRepair');
                                layer.closeAll();
                                //执行跳转
                                var topLayui = parent === self ? layui : top.layui;
                                topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                            }
                        });
                    }
                    );
                }, btn2: function () {
                    layer.closeAll();
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });

</script>